package it.fc.auth;

import it.fc.bean.UserBean;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import fc.utils.FcCostanti;

public class AdminInterceptor extends AbstractInterceptor {

    private static final long serialVersionUID = -6207717748437158137L;

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {

        UserBean user = (UserBean) ActionContext.getContext().getSession().get(FcCostanti.SESSION_USER);

        if (user.isUserInRole(FcCostanti.ROLE_ADMIN)) {
            return FcCostanti.ADMIN_TARGET;
        } else {
            return FcCostanti.LOGIN_TARGET;
        }
    }

}
